#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include "StdThread.h"

Mutex *m1;
Mutex *m2;
//定义一个锁,静态初始化
pthread_mutex_t mutex;//= PTHREAD_MUTEX_INITIALIZER;
int money = 1000;
//zhangsan
void* thread1(void *arg)
{
    MutexLock(m1);
    sleep(1);
    MutexLock(m2);

    printf("thread1线程！\n");

    MutexUnlock(m1);
    MutexUnlock(m2);
}
//lisi
void* thread2(void *arg)
{
    MutexLock(m2);
    sleep(1);
    MutexLock(m1);

    printf("thread2线程！\n");

    MutexUnlock(m1);
    MutexUnlock(m2);
}

int main()
{
    //动态初始化锁
    pthread_mutex_init(&mutex,NULL);
    Thread* t1 = InitThread(thread1,NULL);
    Thread* t2 = InitThread(thread2,NULL); 

    ThreadJoin(t1);
    ThreadJoin(t2);

    ClearThread(t1);
    ClearThread(t2);
    //销毁锁
    pthread_mutex_destroy(&mutex);
    return 0;
}